/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-09-29
 * Time: 19:53
 */
public class isValid_BST {
    long prev = Long.MIN_VALUE;
    public boolean isValidBST(TreeNode root)
    {
        if(root == null) return true;
        boolean left = isValidBST(root.left);
        // 剪枝
        if(left == false) return false;
        boolean cur = false;
        if(root.val > prev) cur = true;
        if(cur == false) return false;
        prev = root.val;
        boolean right = isValidBST(root.right);
        return left && cur && right;
    }

}
